

// 公共类
const pb = {
	api: 'http://wangchao.vipgz6.idcfengye.com/js/a/ba',

	// 审核列表
	applyStateList: [
		{label: '待审批', value: 0},
		{label: '科室主任审核', value: 1},
		{label: '医教科审核', value: 2},
		{label: '信息科审核', value: 3},
		{label: '审批通过', value: 4},
	],

	// 制作状态
	makingStateList: [
		{label: '数据新增', value: 0},
		{label: '新增申请', value: 1},
		{label: '院内审批', value: 2},
		{label: '文件发送', value: 3},
		{label: '文件接收', value: 4},
		{label: '文件下载', value: 5},
		{label: '制定计划', value: 6},
		{label: '建模', value: 7},
		{label: '制模', value: 8},
		{label: '实物交付', value: 9},
		{label: '文件交付', value: 10},
	],

	// 定制部位
	dzbwList: [
		{label: '头部', value: 1},
		{label: '颈部', value: 2},
	],

	// 定制理由
	dzlyList: [
		{label: '术前或术后定制模型，利于医生制定治疗方案和患方沟通、疗效评估', value: 1},
		{label: '个体化精准定制重建修复材料用于治疗', value: 2},
		{label: '其他', value: 3},
	],

	// 影像数据类型
	yxsjlxList: [
		{label: 'CT 或 CTA', value: 1},
		{label: 'MR 或 MRA、MRV', value: 2},
		{label: 'DTI 或 功能成像', value: 3},
	],

	// 确认弹窗
	confirm: function (text) {
		text = text || '此操作将永久删除该文件, 是否继续?';

		var html = '<div class="the-dialog" id="confirmDialog" style="z-index: 9999;">' +
			'<div class="_container">' +
				'<div class="_header">' +
					'<span class="title">提示</span>' +
					'<i class="close-btn icon iconfont iconguanbi"></i>' +
				'</div>' +
				'<div class="_content" style="position: relative;padding: 20px;box-sizing: border-box;min-width: auto;min-height: auto;width: 420px;">' +
					'<i class="icon iconfont icontishi" style="position: absolute;top:50%;margin-top: -12px;font-size: 24px;height: 24px;color: #e6a23c;"></i>' +
					'<p style="padding-left: 30px;line-height:24px;">' + text + '</p>' +
				'</div>' +
				'<div class="_footer" style="padding-top: 5px;border-top: none;">' +
					'<button class="com-btn free close-btn" style="width: auto; height: 32px;">取消</button>' +
					'<button class="com-btn free primary ok-btn" style="width: auto; height: 32px;">确认</button>' +
				'</div>' +
			'</div>' +
		'</div>';
		
		var oConfirm = $(html);
		$(document.body).append(oConfirm);

		var oDialog = new TheDialog('#confirmDialog');
		oDialog.show();

		return new Promise((resolve, reject) => {
			oConfirm.on('click', '.ok-btn', function () {
				oDialog.remove();
				resolve();
			})
			// oConfirm.on('click', 'button.close-btn', function () {
			// 	reject();
			// })
		})
	},

	// 设置列表html
	setSelectOption: function (el, list) {
		var html = '';
		list.forEach(function (item) {
			html += '<option value="' + item.value + '">' + item.label + '</option>'
		})
		$(el).html(html);
	},

	// 根据code获取name
	getNameByCode: function (value, list) {
		var res = '';
		for (var i = 0; i < list.length; i++) {
			var item = list[i];
			if (item.value == value) {
				res = item.label;
				break;
			}
		}
		return res;
	},

	// 判断是否为空
	isEmpty: function (val) {
		if (typeof val == 'string') {
			val = val.trim();
		}
		return !val && val !== 0 && typeof val !== 'boolean' ? true : false;
	},

	storage: {
	    /**
	     * 存储sessionStorage
	     */
	    set: function (name, data) {
	        if (!name) return;
	        name += '_' + location.port;
	        if (typeof data !== 'string') {
	            data = JSON.stringify(data);
	        }
	        window.sessionStorage.setItem(name, data);
	    },
	    /**
	     * 获取sessionStorage
	     */
	    get: function (name) {
	        if (!name) return;
	        name += '_' + location.port;
	        var value = window.sessionStorage.getItem(name);
	        if (value !== null) {
	            try {
	                value = JSON.parse(value);
	            } catch (e) {
	                value = value;
	            }
	        }
	        return value;
	    },
	    /**
	     * 删除sessionStorage
	     * name 为空时  清除所有数据
	     */
	    remove: function (name) {
	        if (!name) {
	            window.sessionStorage.clear();
	        }else {
	        	name += '_' + location.port;
	            window.sessionStorage.removeItem(name);
	        }
	    },
	},

	// 转换时间
	switchTime: function (time, format) {
	 	time = time || '';
		format = format ? format : 'yyyy年MM月dd日 HH:mm:ss';

		var res = format;

		var date = new Date(time);
		var timestamp = date.getTime(),
			year = date.getFullYear(),
			month = date.getMonth() + 1,
			day = date.getDate(),
			hours = date.getHours(),
			minutes = date.getMinutes(),
			seconds = date.getSeconds(),
			week = date.getDay(); // 0是星期日
		var shortHours = hours > 12 ? hours - 12 : hours; // 短时间

		// 判断传入是否可以转换为时间
		if (!year) {
			return time;
		}

		// 替换时间戳
		res = res.replace(/timestamp/g, timestamp);

		// 替换年
		res = res.replace(/yyyy/g, year);

		// 替换月
		res = res.replace(/MM/g, makeUpNum(month));
		res = res.replace(/M/g, month);

		// 替换日
		res = res.replace(/dd/g, makeUpNum(day));
		res = res.replace(/d/g, day);

		// 替换时
		res = res.replace(/HH/g, makeUpNum(hours));
		res = res.replace(/H/g, hours);
		res = res.replace(/hh/g, makeUpNum(shortHours));
		res = res.replace(/h/g, shortHours);

		// 替换分
		res = res.replace(/mm/g, makeUpNum(minutes));
		res = res.replace(/m/g, minutes);

		// 替换秒
		res = res.replace(/ss/g, makeUpNum(seconds));
		res = res.replace(/s/g, seconds);

		// 替换周
		res = res.replace(/WW/g, makeUpNum(week));
		res = res.replace(/W/g, week);

		function makeUpNum (num) {
			return num < 10 ? '0' + num : num;
		}

		return res;
	}
}


